package com.yvon.service.demo.mybatis.mapping;

import com.yvon.service.demo.mybatis.session.Configuration;
import lombok.Data;

import java.util.Map;

/**
 * SQL 信息记录对象，包括记录：SQL类型、SQL语句、入参类型、出参类型等
 *
 * @author yvon
 * @since 2023-03-21
 */
@Data
public class MappedStatement {

    /**
     * 配置
     */
    private Configuration configuration;

    /**
     * id
     * namespace + id
     * mapper+方法
     */
    private String id;

    /**
     * sql命令类型
     */
    private SqlCommandType sqlCommandType;

    /**
     * 绑定sql
     */
    private BoundSql boundSql;

    MappedStatement() {
        // constructor disabled
    }

    public static class Builder {
        private MappedStatement mappedStatement = new MappedStatement();

        public Builder(Configuration configuration, String id, SqlCommandType sqlCommandType, BoundSql boundSql) {
            mappedStatement.configuration = configuration;
            mappedStatement.id = id;
            mappedStatement.sqlCommandType = sqlCommandType;
            mappedStatement.boundSql = boundSql;
        }

        public MappedStatement build() {
            assert mappedStatement.configuration != null;
            assert mappedStatement.id != null;
            return mappedStatement;
        }

    }
}
